import type { DescData } from '@arco-design/web-vue/es/descriptions/interface'
import axios from 'axios'
import qs from 'query-string'

export interface GoodsRecord {
    id: number
    name: string | null
    goodsNo: string | null
    sellPrice: number
    marketPrice: number
    costPrice: number
    storeNums: number
    img: string | null
    brandId: number
    categoryId: number
    sort: number
    isDel: boolean
    sale: number
}

export interface PageQuery {
    current: number
    pageSize: number
    name?: string
    goodsNo?: string
    categoryId?: number
    brandId?: number
}

export interface GoodsPageRes {
    list: GoodsRecord[]
    total: number
}

export interface GoodsDetail {
    id: number
    name: string | null
    goodsNo: string | null
    sellPrice: number
    marketPrice: number
    costPrice: number
    upTime: string | null
    downTime: string | null
    createTime: string | null
    storeNums: number
    img: string | null
    adImg: string | null
    isDel: boolean
    content: string | null
    weight: number
    point: number
    unit: string | null
    brandId: number
    visit: number
    favorite: number
    sort: number
    specArray: string | null
    exp: number
    comments: number
    sale: number
    grade: number
    sellerId: number
    isShare: boolean
    categoryId: number
}

export function getGoodsDetail(id: number) {
    return axios.get<GoodsDetail>(`/api/goods/${id}`)
}

// 添加商品信息
export function createGoods(data: GoodsDetail) {
    return axios.put('/api/goods/add', data)
}


// 编辑商品信息
export function updateGoods(data: GoodsDetail) {
    return axios.put('/api/goods', data)
}

// 删除商品
export function deleteGoods(ids: number[]) {
    return axios.delete('/api/goods', {
        data: ids
    })
}

export function queryGoodsPage(params: PageQuery) {
    return axios.get<GoodsPageRes>('/api/goods/page', {
        params,
        paramsSerializer: (obj) => {
            return qs.stringify(obj)
        },
    })
}
// 启用/禁用分类
export function toggleGoodsStatus(id: number) {
    return axios.put(`/api/goods/enable/${id}`)
}
